﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Encodings;
using System.Text.Json;
using System.Windows.Forms;
using project1113.Wrold;

namespace project1113.Robot
{
    class Commands
    {
        public static int GetPacketID()
        {
            return WorldModel.CurrentWorld.Robot.packID;
        }

        public int packetID { get; set; }
        public string cmd { get; set; }
        public virtual string ToJson()
        {
            return "";
        }
    }
    class P2p : Commands
    {
        public int postion { get; set; }
        public P2p(int position)
        {
            cmd = "p2p";
            postion = position;
            packetID = GetPacketID();
        }
        public override string ToJson()
        {
            return JsonSerializer.Serialize(this);
        }
    }
    class GetItem : Commands
    {
        public int position { get; set; }
        public int item { get; set; }
        public GetItem(int _position, int _item)
        {
            packetID = GetPacketID();
            cmd = "GetItem";
            position = _position;
            item = _item;
        }
        public override string ToJson()
        {
            return JsonSerializer.Serialize(this);
        }
    }
    class HandOver : Commands
    {
        public HandOver()
        {
            packetID = GetPacketID();
            cmd = "HandOver";
        }
        public override string ToJson()
        {
            return JsonSerializer.Serialize(this);
        }
    }
    class LooseHand : Commands
    {
        public LooseHand()
        {
            packetID = GetPacketID();
            cmd = "LooseHand";
        }
        public override string ToJson()
        {
            return JsonSerializer.Serialize(this);
        }
    }
    public class Robot
    {
        public int packID { get;private set; } = 0;
        public string Message { get; private set; }
        public bool isBusy { get; set; } = false;
        public void SendCommand(string date)
        {
            packID++;
            Communication.Communication.sendDate(date);
            isBusy = true;
            //发送数据包
        }
        public void UpdateMessage(string message)
        {
            Message = message;
        }
        public void freeRobot()
        {
            isBusy=false;
        }
    }
    
}
